package com.example.rfidserver.consume.subactivity;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;

import com.example.rfidserver.R;
import com.example.rfidserver.consume.adapter.SiteConsumeAdapter;
import com.example.rfidserver.consume.subactivity.subactivity_siteconsume.AddService;
import com.example.rfidserver.consume.subactivity.subactivity_siteconsume.DelService;
import com.example.rfidserver.consume.subactivity.subactivity_siteconsume.ModifyService;
import com.example.rfidserver.dao.ConsumeDao;
import com.example.rfidserver.dao.UserDao;
import com.example.rfidserver.pojo.Consume;
import com.example.rfidserver.pojo.User;
import com.example.rfidserver.ticket.TicketManagerActivity;
import com.example.rfidserver.ticket.adapter.TicketAdapter;
import com.example.rfidserver.ticket.subactivity.TicketAddActivity;
import com.example.rfidserver.ticket.subactivity.TicketDeleteActivity;
import com.example.rfidserver.ticket.subactivity.TicketModifyActivity;

import java.util.List;

public class SiteConsumeActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_site_consume);
        ConsumeDao consumeDao = new ConsumeDao();
        List<Consume> services = consumeDao.getConsumeInfo();
        initview(this,services);
    }


    @Override
    protected void onResume() {
        super.onResume();
        ConsumeDao consumeDao = new ConsumeDao();
        List<Consume> services = consumeDao.getConsumeInfo();
        initview(this,services);
    }

    public void initview(Context context, List<Consume> services){
        final ListView mylistview = findViewById(R.id.mylistview_site_consume);
        final SiteConsumeAdapter siteConsumeAdapter = new SiteConsumeAdapter(context,services);
        mylistview.setAdapter(siteConsumeAdapter);
        //设置Item项的点击事件
        mylistview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                //得到点击的该用户的所有信息
                Consume item_service = siteConsumeAdapter.getItem(position);
                System.out.println(item_service);
            }
        });
    }

    public void onClick(View view){
        switch (view.getId()){
            case R.id.service_add:
                Intent addintent = new Intent(SiteConsumeActivity.this, AddService.class);
                startActivity(addintent);
                break;
            case R.id.service_mod:
                Intent modintent = new Intent(SiteConsumeActivity.this, ModifyService.class);
                startActivity(modintent);
                break;
            case R.id.service_del:
                Intent delintent = new Intent(SiteConsumeActivity.this, DelService.class);
                startActivity(delintent);
                break;
        }

    }





}
